<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="联盟ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="allianceId">
              <j-dict-select-tag type="list" v-model="model.allianceId" dictCode="ht_alliance,enterprise_name,id" placeholder="请选择联盟ID" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="账户类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountType">
              <j-dict-select-tag type="list" v-model="model.accountType" dictCode="account_type" placeholder="请选择账户类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certificateAuditStatus">
              <j-dict-select-tag type="list" v-model="model.certificateAuditStatus" dictCode="certificate_audit_status" placeholder="请选择资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="注册渠道(0-PC，1-公众号，2-后台）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="channel">
              <j-dict-select-tag type="list" v-model="model.channel" dictCode="sign_up_channel" placeholder="请选择注册渠道(0-PC，1-公众号，2-后台）" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="后台用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysUserId">
              <j-search-select-tag v-model="model.sysUserId" dict="sys_user,username,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产业分类ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryCategoryId">
              <j-dict-select-tag type="list" v-model="model.industryCategoryId" dictCode="ht_industry_category,name,id" placeholder="请选择产业分类ID" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="username">
              <a-input v-model="model.username" placeholder="请输入用户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phoneNumber">
              <a-input v-model="model.phoneNumber" placeholder="请输入手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input v-model="model.email" placeholder="请输入邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="password">
              <a-input v-model="model.password" placeholder="请输入密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseName">
              <a-input v-model="model.enterpriseName" placeholder="请输入企业名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构Logo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logo">
              <j-image-upload isMultiple  v-model="model.logo" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业主图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cover">
              <j-image-upload isMultiple  v-model="model.cover" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avatar">
              <a-input v-model="model.avatar" placeholder="请输入头像"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="introduction">
              <j-editor v-model="model.introduction" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业执照" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certificates">
              <j-image-upload isMultiple  v-model="model.certificates" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他资质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="otherCertificates">
              <j-image-upload isMultiple  v-model="model.otherCertificates" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="税号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxId">
              <a-input v-model="model.taxId" placeholder="请输入税号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccountName">
              <a-input v-model="model.bankAccountName" placeholder="请输入开户银行"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="银行账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccountNum">
              <a-input v-model="model.bankAccountNum" placeholder="请输入银行账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经营模式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessModelId">
              <j-dict-select-tag type="list" v-model="model.businessModelId" dictCode="business_model_category,name,id" placeholder="请选择经营模式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注册资金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registeredCapital">
              <a-input v-model="model.registeredCapital" placeholder="请输入注册资金"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年营业额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yearlyTurnover">
              <a-input v-model="model.yearlyTurnover" placeholder="请输入年营业额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditUsername">
              <a-input v-model="model.auditUsername" placeholder="请输入审核人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">
              <j-dict-select-tag type="list" v-model="model.auditStatus" dictCode="audit_status" placeholder="请选择审核状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditComments">
              <a-input v-model="model.auditComments" placeholder="请输入审批意见"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否冻结" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isLocked">
              <j-dict-select-tag type="list" v-model="model.isLocked" dictCode="is_locked" placeholder="请选择是否冻结" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HTAllianceMemberForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
            accountType:6,
            certificateAuditStatus:0,
            channel:2,
            auditStatus:0,
            isLocked:0,
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           allianceId: [
              { required: true, message: '请输入联盟ID!'},
           ],
           accountType: [
              { required: true, message: '请输入账户类型!'},
           ],
           certificateAuditStatus: [
              { required: true, message: '请输入资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回!'},
           ],
          //  channel: [
          //     { required: true, message: '请输入注册渠道(0-PC，1-公众号，2-后台）!'},
          //  ],
          //  sysUserId: [
          //     { required: true, message: '请输入后台用户!'},
          //  ],
           industryCategoryId: [
              { required: true, message: '请输入产业分类ID!'},
           ],
           username: [
              { required: true, message: '请输入用户名!'},
           ],
           phoneNumber: [
              { required: true, message: '请输入手机号!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
           email: [
              { required: true, message: '请输入邮箱!'},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
           ],
          //  password: [
          //     { required: true, message: '请输入密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)!'},
          //  ],
           enterpriseName: [
              { required: true, message: '请输入企业名称!'},
           ],
           logo: [
              { required: true, message: '请输入机构Logo!'},
           ],
           cover: [
              { required: true, message: '请输入企业主图!'},
           ],
           introduction: [
              { required: true, message: '请输入简介!'},
           ],
           certificates: [
              { required: true, message: '请输入营业执照!'},
           ],
           registeredCapital: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           yearlyTurnover: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           auditStatus: [
              { required: true, message: '请输入审核状态!'},
           ],
           isLocked: [
              { required: true, message: '请输入是否冻结!'},
           ],
        },
        url: {
          add: "/account/hTAllianceMember/add",
          edit: "/account/hTAllianceMember/edit",
          queryById: "/account/hTAllianceMember/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>